package com.tengol.demo.design.pattern.structural.facade;

import com.tengol.demo.design.pattern.structural.facade.domain.PointGift;
import com.tengol.demo.design.pattern.structural.facade.subsystem.ExpressDeliveryService;
import com.tengol.demo.design.pattern.structural.facade.subsystem.PointPaymentService;
import com.tengol.demo.design.pattern.structural.facade.subsystem.PointQualifyService;

/**
 * 积分兑换门面服务
 *
 * @author dongrui
 * @date 2019/03/05
 */
public class GiftExchangeFacadeService {
    private PointQualifyService pointQualifyService;
    private PointPaymentService pointPaymentService;
    private ExpressDeliveryService expressDeliveryService;

    public GiftExchangeFacadeService(){
        this.pointQualifyService = new PointQualifyService();
        this.pointPaymentService = new PointPaymentService();
        this.expressDeliveryService = new ExpressDeliveryService();
    }

    public void exchangeGift(PointGift pointGift){
        //1.校验积分是否足够
        if(pointQualifyService.isAvailable(pointGift)){
            //2.积分兑换礼物
            if(pointPaymentService.pay(pointGift)){
                //3.交付给快递
                String deliveryNum = expressDeliveryService.deliveryGift(pointGift);
                System.out.println("交付给快递公司，快递单号：" + deliveryNum);
            }
        }
    }
}
